paned: Split out a function
authorBenjamin Otte <otte@redhat.com>
Mon, 29 Apr 2013 16:20:22 +0000 (18:20 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 1 May 2013 14:41:11 +0000 (16:41 +0200)
gtk/gtkpaned.c

index 3203cea0ca25fb2febadfce99071f055775be80e..cc1cb13e33d422cd6e463e3eb4959af3669f6de8 100644 (file)
@@ -870,6 +870,62 @@ gtk_paned_finalize (GObject *object)
   G_OBJECT_CLASS (gtk_paned_parent_class)->finalize (object);
 }
 
+static void
+gtk_paned_compute_position (GtkPaned *paned,
+                            gint      allocation,
+                            gint      child1_req,
+                            gint      child2_req,
+                            gint     *min_pos,
+                            gint     *max_pos,
+                            gint     *out_pos)
+{
+  GtkPanedPrivate *priv = paned->priv;
+  gint min, max, pos;
+
+  min = priv->child1_shrink ? 0 : child1_req;
+
+  max = allocation;
+  if (!priv->child2_shrink)
+    max = MAX (1, max - child2_req);
+  max = MAX (min, max);
+
+  if (!priv->position_set)
+    {
+      if (priv->child1_resize && !priv->child2_resize)
+       pos = MAX (0, allocation - child2_req);
+      else if (!priv->child1_resize && priv->child2_resize)
+       pos = child1_req;
+      else if (child1_req + child2_req != 0)
+       pos = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5;
+      else
+       pos = allocation * 0.5 + 0.5;
+    }
+  else
+    {
+      /* If the position was set before the initial allocation.
+       * (priv->last_allocation <= 0) just clamp it and leave it.
+       */
+      if (priv->last_allocation > 0)
+       {
+         if (priv->child1_resize && !priv->child2_resize)
+           pos = priv->child1_size + allocation - priv->last_allocation;
+         else if (!(!priv->child1_resize && priv->child2_resize))
+           pos = allocation * ((gdouble) priv->child1_size / (priv->last_allocation)) + 0.5;
+       }
+      else
+        pos = min;
+    }
+
+  pos = CLAMP (pos, min, max);
+  
+  if (min_pos)
+    *min_pos = pos;
+  if (max_pos)
+    *max_pos = pos;
+  if (out_pos)
+    *out_pos = pos;
+}
+
 static void
 gtk_paned_get_preferred_size (GtkWidget      *widget,
                               GtkOrientation  orientation,
@@ -2064,41 +2120,10 @@ gtk_paned_calc_position (GtkPaned *paned,
   old_min_position = priv->min_position;
   old_max_position = priv->max_position;
 
-  priv->min_position = priv->child1_shrink ? 0 : child1_req;
-
-  priv->max_position = allocation;
-  if (!priv->child2_shrink)
-    priv->max_position = MAX (1, priv->max_position - child2_req);
-  priv->max_position = MAX (priv->min_position, priv->max_position);
-
-  if (!priv->position_set)
-    {
-      if (priv->child1_resize && !priv->child2_resize)
-       priv->child1_size = MAX (0, allocation - child2_req);
-      else if (!priv->child1_resize && priv->child2_resize)
-       priv->child1_size = child1_req;
-      else if (child1_req + child2_req != 0)
-       priv->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req)) + 0.5;
-      else
-       priv->child1_size = allocation * 0.5 + 0.5;
-    }
-  else
-    {
-      /* If the position was set before the initial allocation.
-       * (priv->last_allocation <= 0) just clamp it and leave it.
-       */
-      if (priv->last_allocation > 0)
-       {
-         if (priv->child1_resize && !priv->child2_resize)
-           priv->child1_size += allocation - priv->last_allocation;
-         else if (!(!priv->child1_resize && priv->child2_resize))
-           priv->child1_size = allocation * ((gdouble) priv->child1_size / (priv->last_allocation)) + 0.5;
-       }
-    }
-
-  priv->child1_size = CLAMP (priv->child1_size,
-                             priv->min_position,
-                             priv->max_position);
+  gtk_paned_compute_position (paned,
+                              allocation, child1_req, child2_req,
+                              &priv->min_position, &priv->max_position,
+                              &priv->child1_size);
 
   if (priv->child1)
     gtk_paned_set_child_visible (paned, 0, priv->child1_size != 0);